using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Fody;

public class InnerWeaver : MarshalByRefObject
{
    public BuildLogger Logger;
    public string AssemblyPath;
    public string References;
    public IList<WeaverEntry> Weavers;
    public string KeyFilePath;
    
    public void Execute()
    {
        var referenceFinder = new AssemblyReferenceFinder(this, Logger);
        referenceFinder.Execute();

        var assemblyResolver = new AssemblyResolver(referenceFinder);
        var reader = new ModuleReader
                            {
                                AssemblyResolver = assemblyResolver,
                                InnerWeaver = this,
                                Logger = Logger
                            };
        reader.Execute();

        var weaverInitialiser = new WeaverInitialiser
                                    {
                                        ModuleDefinition = reader.ModuleDefinition,
                                        AssemblyResolver = assemblyResolver,
                                        InnerWeavingTask = this,
                                        Logger = Logger
                                    };
        weaverInitialiser.Execute();

        var weaverRunner = new ModuleWeaverRunner
                                {
                                    Logger = Logger,
                                    WeaverInitialiser = weaverInitialiser
                                };
        weaverRunner.Execute();

        var moduleWriter = new ModuleWriter
                                {
                                    InnerWeaver = this,
                                    Logger = Logger,
                                    ModuleDefinition = reader.ModuleDefinition
                                };
        moduleWriter.Execute();
    }
}